<?php

@ob_start();

$_SERVER['IN_ADMIN']    = true;
$_SERVER['BASE_PATH']   = dirname(__FILE__) . '/';

require_once $_SERVER['BASE_PATH'] . 'lib/' . 'config.php';
require_once $_SERVER['BASE_PATH'] . 'lib/' . 'mysql.php';
require_once $_SERVER['BASE_PATH'] . 'lib/' . 'param.php';
require_once $_SERVER['BASE_PATH'] . 'lib/' . 'url.php';
require_once $_SERVER['BASE_PATH'] . 'lib/' . 'page.php';
require_once $_SERVER['BASE_PATH'] . 'lib/' . 'front.php';

$_SERVER['BASE_URL']    = url_get_current_path() . '/';

$title = '标题'; // default title



$content = false;

if(!empty($_GET['module'])){
    // call module 

}elseif(!empty($_GET['page'])){
    $page = $_GET['page'];

    if(preg_match('#^[A-Za-z0-9_\-]+$#', $page)){
        // try page from /page/
        if(!$content){
            if( file_exists('./page/' . $page . '.html')){
                $content = file_get_contents('./page/' . $page . '.html');
            }
        }
        
        // try page from db
        if(!$content){
            $content = page_get($page);
        }

    }

}else{
    // index

    $content = front_get();
}


if(!$content){
    // 404
    $content = page_404();
}

$ob_out = @ ob_get_clean();

require_once 'template/header.php';
echo $content;
require_once 'template/footer.php';


